/*
** player.c for zomzom in /home/goupil_r//GameInLab/game1
**
** Made by robin goupil
** Login   <goupil_r@epitech.net>
**
** Started on  Thu Nov 15 17:22:06 2012 robin goupil
** Last update Sun Nov 18 16:22:04 2012 robin goupil
*/

#include <SDL/SDL.h>
#include <math.h>
#include "include/SDL/SDL_image.h"
#include "include/struct.h"
#include "include/player.h"
#include "include/zombie.h"
#include "include/world.h"
#include "include/collision.h"
#include "include/my.h"

#define WEAPONS_NUMBER 1

t_biped		*create_biped(t_sprite *sprite, t_vec *pos, double acceleration, int health)
{
  t_biped	*biped;

  biped = xmalloc(sizeof(*biped));
  biped->acceleration = acceleration;
  biped->pos = *pos;
  biped->speed_x = 0;
  biped->speed_y = 0;
  biped->max_speed = 2;
  biped->sprite = sprite;
  biped->rotation = 0;
  biped->health = health;
  return (biped);
}

t_weapon	*create_weapon(SDL_Surface *sprite, int damage)
{
  t_weapon	*weapon;

  weapon = xmalloc(sizeof(weapon));
  weapon->sprite = sprite;
  weapon->damage = damage;
  return (weapon);
}

t_player	*create_player(t_sprite *sprite, t_vec *pos)
{
  t_player	*player;

  player = xmalloc(sizeof(*player));
  player->biped = create_biped(sprite, pos, 0.1, 100);
  player->weapon_list = xmalloc(sizeof(t_weapon *) * WEAPONS_NUMBER);
  player->current_weapon = NULL;
  return (player);
}

t_reticle	*create_reticle(t_sprite *sprite, t_vec *pos)
{
  t_reticle	*reticle;

  reticle = xmalloc(sizeof(*reticle));
  reticle->sprite = sprite;
  reticle->pos = *pos;
  return (reticle);
}

t_sprite	*new_sprite(char *path, int size)
{
  t_sprite	*sprite;

  sprite = malloc(sizeof(*sprite));
  sprite->image = IMG_Load(path);
  if (!(sprite->image))
    {
      printf("Error when loading sprite %s.\n", path);
      exit(EXIT_FAILURE);
    }
  sprite->size = size;
  return (sprite);
}
